package com.example.demo.practice;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.demo.practice.tool.ImageGroupID;
import com.example.demo.practice.ui.MenuTitle;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created by dm on 16-3-29.
 * 第一个页面
 */
public class Table5 extends Fragment {
    private String user = "";
    ListView listView;
    private List<info> mlistInfo = new ArrayList();
    private String next = "";
    private String select = "";
    private String title = "";

    public Table5() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.tab05, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initGridView();
    }

    /**
     * 初始化网格视图
     */
    private void initGridView() {
        MenuTitle menuTitle1=(MenuTitle) getActivity().findViewById(R.id.device_manager);
        MenuTitle menuTitle2=(MenuTitle) getActivity().findViewById(R.id.device_maintain);
        MenuTitle menuTitle3=(MenuTitle) getActivity().findViewById(R.id.device_statistics);

        ImageGroupID imageGroupID=new ImageGroupID(getActivity());
        int[] icon1 = imageGroupID.getImageGroupID(R.array.device_manager_image);
        int[] icon2 = imageGroupID.getImageGroupID(R.array.device_maintain_image);
        int[] icon3 = imageGroupID.getImageGroupID(R.array.device_statistics_image);

        String[] iconName1 = getResources().getStringArray(R.array.device_manager);
        String[] iconName2=getResources().getStringArray(R.array.device_maintain);
        String[] iconName3=getResources().getStringArray(R.array.device_statistics);

        menuTitle1.setView(icon1,iconName1);
        menuTitle2.setView(icon2,iconName2);
        menuTitle3.setView(icon3,iconName3);

        menuTitle1.setOnItemClickListener(new Listener1());
        menuTitle2.setOnItemClickListener(new Listener2());
        menuTitle3.setOnItemClickListener(new Listener3());
    }

    private class Listener1 implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String activityName = "";
            switch (i){
                case 0:activityName = "com.example.demo.practice.enterprisemanager.BreakList";
                    next = "com.example.demo.practice.dashboardview.CheckInfo";
                    select = "正常";
                    title = "接入审核";
                    break;
                case 1:activityName = "com.example.demo.practice.enterprisemanager.BreakList";
                    next = "com.example.demo.practice.dashboardview.ChangeInfo";
                    select = "故障";
                    title = "变更审核";
                    break;
                case 2:activityName = "com.example.demo.practice.dashboardview.FacilityIfs";
                    break;
                case 3:activityName = "com.example.demo.practice.enterprisemanager.TourAdm";
                    break;
                default:break;
            }

            //动态界面跳转
            if (!Objects.equals(activityName, "")) {
                try {
                    Intent intent = new Intent(getActivity(), Class.forName(activityName));
                    intent.putExtra("next",next);
                    intent.putExtra("select",select);
                    intent.putExtra("title",title);
                    startActivity(intent);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private class Listener2 implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String activityName = "";
            switch (i){
                case 0:activityName = "com.example.demo.practice.dashboardview.FacilityStatus";
                    break;
                case 1:activityName = "com.example.demo.practice.monitoring.AllBreakList";
                    break;
                default:break;
            }

            //动态界面跳转
            if (!Objects.equals(activityName, "")) {
                try {
                    Intent intent = new Intent(getActivity(), Class.forName(activityName));
                    startActivity(intent);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private class Listener3 implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String activityName = "";
            switch (i){
                case 0:activityName = "com.example.demo.practice.mychart.EtpDistribute";
                    break;
                case 1:activityName = "com.example.demo.practice.mychart.EtpFacilities";
                    break;
                case 2:activityName = "com.example.demo.practice.enterprisemanager.RepairRecord";
                    break;
                case 3:activityName = "com.example.demo.practice.enterprisemanager.BreakHistory";
                    break;
                case 4:activityName = "com.example.demo.practice.devices.InspectionHistory";
                    break;
                default:break;
            }

            //动态界面跳转
            if (!Objects.equals(activityName, "")) {
                try {
                    Intent intent = new Intent(getActivity(), Class.forName(activityName));
                    startActivity(intent);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}